import React, { useState } from 'react';
import Web3 from 'web3';
import Marketplace from '../artifacts/contracts/Marketplace.sol/Marketplace.json';

const RemoveProduct = () => {
    const [productId, setProductId] = useState('');

    const web3 = new Web3(Web3.givenProvider);
    const marketplaceAddress = "YOUR_MARKETPLACE_CONTRACT_ADDRESS";
    const marketplaceContract = new web3.eth.Contract(Marketplace.abi, marketplaceAddress);
    const removeProduct = async () => {
        try {
            const accounts = await web3.eth.requestAccounts();
            await marketplaceContract.methods.removeProduct(productId).send({ from: accounts[0] });
            alert('商品下架成功');
        } catch (error) {
            console.error('商品下架失败', error);
        }
    };

    return (
        <div>
            <h2>下架商品</h2>
            <input type="number" placeholder="商品ID" value={productId} onChange={(e) => setProductId(e.target.value)} />
            <button onClick={removeProduct}>下架</button>
        </div>
    );
};

export default RemoveProduct;
